<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户中心</title>
<include file="public:header" />
</head>
<body>
<div id="header" class="layui-bg-cyan">
	<div class="layui-container">
		<div class="fl">
			<li class="nav-item active"><a href="/" class="nav-link">返回</a></li>
		</div>
		<div class="fr">
			<li class="nav-item"><a href="/user/index" class="nav-link"><img src="{$data.avatar}" alt="{$data.name}">{$data.nickname|default=$data.name}</a>
		</div>
	</div>
</div>
<div id="content">
	<div class="layui-clear" ></div>
	<div class="layui-container">
		<div class="layui-row layui-col-space30">
			<div class="layui-col-md3">

				<div class="layui-card">
					<div class="layui-card-header layui-bg-cyan">导航</div>
					<div class="layui-card-body" id="userNav" >
						<include file="/user/userNav">
					</div>					
				</div>		   
		    </div>
		    <div class="layui-col-md9">

				<div class="layui-card" >
					<div class="layui-card-header layui-bg-cyan">修改密码</div>
					<div class="layui-card-body" style="overflow:hidden;" >
					
						<form action="/user/changepwd" class="layui-form layui-form-fixed">
							<input type="text" name="name" value="{$data.name}" hidden="">
							<div class="layui-form-item">
								<label class="layui-form-label">原密码</label>
								<div class="layui-input-inline">
								  <input type="text" id="oldpwd" name="oldpwd" class="layui-input" >
								</div>
							</div>		
							<div class="layui-form-item">
								<label class="layui-form-label">新密码</label>
								<div class="layui-input-inline">
								  <input type="password" id="pwd" name="pwd" class="layui-input" >
								</div>
							</div>		
							<div class="layui-form-item">
								<label class="layui-form-label">确认密码</label>
								<div class="layui-input-inline">
								  <input type="password" id="repwd" name="repwd" class="layui-input" >
								</div>
							</div>	

							<div class="layui-form-item" style="margin-top: 22px;text-align: center;">
								<button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="submit">立即提交</button>
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
							</div>												
						</form>
						
					</div>
				</div>
			</div>		    			
		</div>
	</div>
</div>
<include file="public:footer"/>
</body>
<script>
	layui.use(['jquery','form'],function(){
		var $ = layui.jquery;
		var form = layui.form;

		 //监听提交
		form.on('submit(submit)', function(data){
			
			if($("#pwd").val().length < 6){
				layer.tips('请至少输入6个字符作为密码',"#pwd",{'tips':3});
				return false;
			}

			if ($("#pwd").val() !== $("#repwd").val()) {
				layer.tips('两次输入的密码不一样！',"#repwd",{'tips':3});
				return false;
			}			

			$.ajax({
				url: $(this).attr('action'),
				type: 'POST',
				dataType: 'json',
				timeout: 6000,
				data: data.field,
				success: function(res){
					layer.msg(res.msg);
					if (res.code == 200) {
						top.location.reload();
					}

				}
			});

			return false;
		});
		
	})
</script>
</html>